namespace Easy.Authorization.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class first : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Aut_Columns",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        RoleId = c.Guid(nullable: false),
                        FunctionId = c.Guid(nullable: false),
                        AllowRead = c.Boolean(),
                        AllowWrite = c.Boolean(),
                        Criteria = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Aut_Roles", t => t.RoleId, cascadeDelete: true)
                .Index(t => t.RoleId);
            
            CreateTable(
                "dbo.Aut_Roles",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        RoleName = c.String(nullable: false, maxLength: 50),
                        RoleDescription = c.String(maxLength: 50),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Aut_RoleModelMaps",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        RoleId = c.Guid(nullable: false),
                        ModelId = c.Guid(nullable: false),
                        AllowRead = c.Boolean(),
                        AllowWrite = c.Boolean(),
                        AllowCreate = c.Boolean(),
                        AllowDelete = c.Boolean(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Aut_Models", t => t.ModelId, cascadeDelete: true)
                .ForeignKey("dbo.Aut_Roles", t => t.RoleId, cascadeDelete: true)
                .Index(t => t.RoleId)
                .Index(t => t.ModelId);
            
            CreateTable(
                "dbo.Aut_Models",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        ModelName = c.String(nullable: false, maxLength: 50),
                        ModelDispaly = c.String(nullable: false, maxLength: 50),
                        ModelUrl = c.String(maxLength: 500),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Aut_RoleNavigateMaps",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        RoleId = c.Guid(nullable: false),
                        NavigationId = c.Guid(nullable: false),
                        AllowNavigate = c.Boolean(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Aut_Navigations", t => t.NavigationId, cascadeDelete: true)
                .ForeignKey("dbo.Aut_Roles", t => t.RoleId, cascadeDelete: true)
                .Index(t => t.RoleId)
                .Index(t => t.NavigationId);
            
            CreateTable(
                "dbo.Aut_Navigations",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        NavigationKey = c.String(nullable: false, maxLength: 50),
                        NavigationDispaly = c.String(nullable: false, maxLength: 50),
                        NavigationUrl = c.String(nullable: false),
                        ParentId = c.Guid(),
                        ParentChain = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Aut_Navigations", t => t.ParentId)
                .Index(t => t.ParentId);
            
            CreateTable(
                "dbo.Aut_Rows",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        RoleId = c.Guid(nullable: false),
                        FunctionId = c.Guid(nullable: false),
                        AllowRead = c.Boolean(),
                        AllowWrite = c.Boolean(),
                        AllowDelete = c.Boolean(),
                        AllowNavigate = c.Boolean(),
                        Criteria = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Aut_Roles", t => t.RoleId, cascadeDelete: true)
                .Index(t => t.RoleId);
            
            CreateTable(
                "dbo.Aut_UserRoleMaps",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        UserId = c.Guid(nullable: false),
                        RoleId = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Aut_Roles", t => t.RoleId, cascadeDelete: true)
                .ForeignKey("dbo.Aut_Users", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.RoleId);
            
            CreateTable(
                "dbo.Aut_Users",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Username = c.String(nullable: false, maxLength: 50),
                        Password = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Aut_Columns", "RoleId", "dbo.Aut_Roles");
            DropForeignKey("dbo.Aut_UserRoleMaps", "UserId", "dbo.Aut_Users");
            DropForeignKey("dbo.Aut_UserRoleMaps", "RoleId", "dbo.Aut_Roles");
            DropForeignKey("dbo.Aut_Rows", "RoleId", "dbo.Aut_Roles");
            DropForeignKey("dbo.Aut_RoleNavigateMaps", "RoleId", "dbo.Aut_Roles");
            DropForeignKey("dbo.Aut_RoleNavigateMaps", "NavigationId", "dbo.Aut_Navigations");
            DropForeignKey("dbo.Aut_Navigations", "ParentId", "dbo.Aut_Navigations");
            DropForeignKey("dbo.Aut_RoleModelMaps", "RoleId", "dbo.Aut_Roles");
            DropForeignKey("dbo.Aut_RoleModelMaps", "ModelId", "dbo.Aut_Models");
            DropIndex("dbo.Aut_UserRoleMaps", new[] { "RoleId" });
            DropIndex("dbo.Aut_UserRoleMaps", new[] { "UserId" });
            DropIndex("dbo.Aut_Rows", new[] { "RoleId" });
            DropIndex("dbo.Aut_Navigations", new[] { "ParentId" });
            DropIndex("dbo.Aut_RoleNavigateMaps", new[] { "NavigationId" });
            DropIndex("dbo.Aut_RoleNavigateMaps", new[] { "RoleId" });
            DropIndex("dbo.Aut_RoleModelMaps", new[] { "ModelId" });
            DropIndex("dbo.Aut_RoleModelMaps", new[] { "RoleId" });
            DropIndex("dbo.Aut_Columns", new[] { "RoleId" });
            DropTable("dbo.Aut_Users");
            DropTable("dbo.Aut_UserRoleMaps");
            DropTable("dbo.Aut_Rows");
            DropTable("dbo.Aut_Navigations");
            DropTable("dbo.Aut_RoleNavigateMaps");
            DropTable("dbo.Aut_Models");
            DropTable("dbo.Aut_RoleModelMaps");
            DropTable("dbo.Aut_Roles");
            DropTable("dbo.Aut_Columns");
        }
    }
}
